package com.lc.pianostudent.dialog;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.BackgroundColorSpan;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.lc.pianostudent.R;
import com.zcx.helper.dialog.AppDialog;
import com.zcx.helper.util.UtilApp;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2017/8/12.
 */

public abstract class RegisterDialog extends AppDialog {
    private int layoutResId;
    private String tishi_text = "";
    public RegisterDialog(Context context, int layoutResId , String tishi_text) {

        super(context, R.style.TradeDialog);
        this.layoutResId = layoutResId;
        this.tishi_text = tishi_text;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(layoutResId);

        Window window = this.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        window .setGravity(Gravity.CENTER);
        lp.dimAmount = 0.1f;
        window .setAttributes(lp);

        this.setCanceledOnTouchOutside(true);
        View.OnClickListener listener = new View.OnClickListener() {

            @Override
            public void onClick(View view) {

                switch (view.getId()) {

                    case R.id.queding:

                        confirm();

                        break;

                    case R.id.phone:

                        phone();

                        break;


                }

                dismiss();

            }

        };



        findViewById(R.id.queding).setOnClickListener(listener);
        TextView money = findViewById(R.id.tishi_text);
        findViewById(R.id.phone).setOnClickListener(listener);

//        //设置超链接可点击
//        money.setMovementMethod(LinkMovementMethod.getInstance());
        final SpannableStringBuilder spannable = new SpannableStringBuilder("您的老师还没有注册，请您拨打电话"+tishi_text+"我们为您解决");
        //BackgroundColorSpan设置背景颜色为绿色  
        spannable.setSpan(new ForegroundColorSpan(Color.parseColor("#10b5f5")),16, spannable.length()-6,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //这个一定要记得设置，不然点击不生效
        money.setMovementMethod(LinkMovementMethod.getInstance());
        spannable.setSpan(new UnderlineSpan(),16, spannable.length()-6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannable.setSpan(new TextClick(),16, spannable.length()-6 , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        money.setText(spannable);



    }

//    private SpannableString getString(){
//        final SpannableStringBuilder spannable = new SpannableStringBuilder("您的老师还没有注册，请您拨打电话"+tishi_text+"我们为您解决");
//        //BackgroundColorSpan设置背景颜色为绿色  
//        spannable.setSpan(new ForegroundColorSpan(Color.RED),2,4,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        //这个一定要记得设置，不然点击不生效
//        textView.setMovementMethod(LinkMovementMethod.getInstance());
//        spannable.setSpan(new TextClick(),2,4 , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        textView.setText(spannable);
//
//
//        //UnderlineSpan设置下划线        
//         spannableString.setSpan(new UnderlineSpan(),16, spannableString.length()-6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//
//        //设置可点击的单击事件监听        
//         spannableString.setSpan(new ClickableSpan() {
//             @Override
//             public void onClick(View widget) {
//                 UtilApp.call(tishi_text);
//               }
//         }, 16, spannableString.length()-6,  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        return spannableString;
//
//
//    }
//


    private class TextClick extends ClickableSpan{
        @Override
        public void onClick(View widget) {
            //在此处理点击事件
            UtilApp.call(tishi_text);
        }

        @Override
        public void updateDrawState(TextPaint ds) {
//            ds.setColor(ds.linkColor);
//            ds.setUnderlineText(true);
        }
    }

    public abstract void confirm();
    public abstract void phone();
}
